import { baseUrl2 } from "./login2";
import customFetch from "@/utils/request";

// 获取全部房源信息
export const getHouseInfoApi = (start = 1, count = 10, zh_properties = '', area = '', decoration = '', house_type = '') => {
  return fetch(`${baseUrl2}/baseinfo/house?start=${start}&count=${count}&zh_properties=${zh_properties}&area=${area}&decoration=${decoration}&house_type=${house_type}`, {
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('adminToken2')}`
    }
  })
}

// 获取指定房源详情
export const getHouseInfoByIdApi = id => {
  return fetch(`${baseUrl2}/baseinfo/house/${id}`, {
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('adminToken2')}`
    }
  })
}

// 删除指定房源信息
export const deleteHouseInfoApi = id => {
  return fetch(`${baseUrl2}/baseinfo/house/${id}`, {
    method: 'DELETE',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('adminToken2')}`
    }
  })
}

// 添加指定房源信息
export const addHouseInfoApi = (obj) => {
  obj.sequence = obj.id
  delete obj.id
  return fetch(`${baseUrl2}/baseinfo/addhouse`, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('adminToken2')}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(obj)
  })
}

// 修改指定房源信息
export const updateHouseInfoApi = (obj) => {
  const id = obj.id
  delete obj.id
  return fetch(`${baseUrl2}/baseinfo/update/${id}`, {
    method: 'PUT',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('adminToken2')}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(obj)
  })
}

// 获取全部设备信息
export const getDeviceInfoApi = (start = 1, count = 10) => {
  return fetch(`${baseUrl2}/baseinfo/devices?start=${start}&count=${count}`, {
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('adminToken2')}`
    }
  })
}

// 获取所有设备的类型
export const getDeviceTypeApi = () => {
  return fetch(`${baseUrl2}/baseinfo/devices/type`, {
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('adminToken2')}`
    }
  })
}

// 获取指定设备类型
export const getDeviceTypeByIdApi = (type, start = 1, count = 10) => {
  return customFetch(`${baseUrl2}/baseinfo/devices/type/byid?type=${type}&start=${start}&count=${count}`, {
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('adminToken2')}`
    }
  })
}

// 模糊查询设备编号
export const getDeviceByIdApi = (id, start = 1, count = 10) => {
  return customFetch(`${baseUrl2}/baseinfo/devices/byid?id=${id}&start=${start}&count=${count}`, {
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('adminToken2')}`
    }
  })
}

// 删除设备信息
export const deleteDeviceInfoApi = id => {
  return customFetch(`${baseUrl2}/baseinfo/devices/${id}`, {
    method: 'DELETE',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('adminToken2')}`
    }
  })
}

// 获取指定id的设备信息
export const getDeviceInfoByIdApi = id => {
  return fetch(`${baseUrl2}/baseinfo/devices/${id}`, {
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('adminToken2')}`
    }
  })
}

// 修改设备信息
export const updateDeviceInfoApi = (obj, id) => {
  return fetch(`${baseUrl2}/baseinfo/update/devices/${id}`, {
    method: 'PUT',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('adminToken2')}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(obj)
  })
}

// 添加设备信息
export const addDeviceInfoApi = (obj) => {
  return fetch(`${baseUrl2}/baseinfo/add/devices`, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('adminToken2')}`,
      'Content-Type': 'application/json'
    },
    body:JSON.stringify(obj)
  })
}